﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset = "UTF-8">
    <script src="{{url_for('static',filename='js/jquery.min.js')}}"></script>
    <script src="{{url_for('static',filename='js/ztReasonEditor.js')}}?{{version}}"></script>
    <script src="{{url_for('static',filename='js/bootstrap.min.js')}}"></script>
    <link rel="stylesheet" href="{{url_for('static',filename='css/bootstrap.min.css')}}">
    <style>
    .button{
        background-color: white;
        color: black;
        border: 2px solid #4CAF50;
    }

    .button:hover {
        background-color: #4CAF50;
        color: white;
    }

    .button[disabled] {
        opacity: 0.6;
        cursor: not-allowed;
    }

    </style>
    <title>涨停原因编辑</title>
</head>
<body>
        <nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
    <div class="navbar-header">
        <a class="navbar-brand" href="#">盯盘宝后台管理系统</a>
    </div>
    <div>
        <ul class="nav navbar-nav">
            <li ><a href="{{ url_for('start_web') }}">首页</a></li>
            <li ><a href="{{ url_for('permission_manage') }}">权限配置</a></li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    管理员{{ session['admin'] if session['admin'] else "未登录" }}
                    <b class="caret"></b>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="{{ url_for("login_out") }}">退出</a></li>
                </ul>
            </li>
        </ul>
    </div>
    </div>
</nav>

<div id="add-block" align="center">
<div style="width:20%;">
 <div class="input-group">
     <input type="text" class="form-control" id="stock-input" />
     <span class="input-group-addon"><a href="#" onclick="searchStock()"><i class="glyphicon glyphicon-search"> <span>搜索</span></i></a></span>
 </div>
</div>
</div>

<div id="client_manage" style="margin:auto; width:95%">

    <br/>
    <div id="dateDiv" align="center">
        <select id="date" class="form-control" style="margin:0px 20px 0px 0px;width:auto;"></select>
    </div>
    <br/>
    <div class="row" align="center">
    <div class="btn-group" >
          <button id="source-button" type="button" class="btn btn-primary">全部</button>
          <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <span class="caret"></span>
            <span class="sr-only">Toggle Dropdown</span>
          </button>
          <ul class="dropdown-menu">
            <li><a href="#" onclick="selectSource('全部')">全部</a></li>
            <li><a href="#" onclick="selectSource('开盘啦')">开盘啦</a></li>
            <li><a href="#" onclick="selectSource('选股宝')">选股宝</a></li>
            <li><a href="#" onclick="selectSource('财联社')">财联社</a></li>
          </ul>
    </div>
    </div>
    <br/>
    <br/>
    <div style="margin:auto">

    <div id="clientManageDataTable" class="table table-striped table-bordered" cellspacing="0" width="95%">
    </div>
    </div>

</div>


<script>

    function searchStock() {
        var stock = $("#stock-input").val();
        if (stock== ""){
            alert("请输入股票");
            return;
        }
        var filterResultList = resultList.filter(function (item) {
            return (item["stock_code"].indexOf(stock)>-1)|(item["stock_name"].indexOf(stock)>-1);
            });
        clientManageDataTable.data(filterResultList, 'code');
    }

    function selectSource(type) {
        $("#source-button").text(type);
        if (type == "全部"){
            var filterResultList = resultList;
        }else{
            var filterResultList = resultList.filter(function (item) {
            return item["source"] == type;
            });
        }
        clientManageDataTable.data(filterResultList, 'code');
    }

        var resultList = null;
        function editorAccount(stock_name,source) {
            var buttonList = $(".button.editor");
            var hasEditoring = false;
            buttonList.each(function (key, value) {
                if ($(value).prop("disabled") == true) {
                    hasEditoring = true;
                    var className = $(value).attr('class').split(' ')[2];
                    window.alert("请先完成对" + className + "的编辑!");
                    return false;
                }
            });
            if (hasEditoring == true) {
                return;
            }
            $("." + stock_name+"."+source).removeAttr("disabled");
            $(".editor.button." + stock_name+"."+source).attr("disabled", "true");

        }

        function submit(stock_name,source) {
            if (source == 'kpl'){
                var reason = $(".reason." + stock_name+"." + source).val();
            }else{
                var reason = "";
            }
            var concept1 = $(".concept1." + stock_name+"." + source).val();
            var concept2 = $(".concept2." + stock_name+"." + source).val();
            var concept3 = $(".concept3." + stock_name+"." + source).val();
            var concept4 = $(".concept4." + stock_name+"." + source).val();
            $.ajax({
                url: "/updateZtReason",
                async: true,
                type: 'POST',
                data: JSON.stringify({'stock_code': stock_name, 'source': source,'date':$("#date").val(),
                    'concept1':concept1, 'concept2': concept2,'concept3':concept3,'concept4':concept4,"reason":reason}),
                dataType: 'json',
                success: function (result) {
                    var message = result.message;
                    alert(message);
                    $("." + stock_name+"."+source).attr("disabled","true");
                    $(".editor.button." + stock_name+"."+source).removeAttr("disabled");
                }
            });

        }

        var clientManageDataTable = null;


        clientManageDataTable = jQuery("#clientManageDataTable").raytable({
            datasource: {data: [], keyfield: 'code'},
            columns: [
                {field: "reason", title: "原因"},
                {field: "concept1", title: "概念1"},
                {field: "concept2", title: "概念2"},
                {field: "concept3", title: "概念3"},
                {field: "concept4", title: "概念4"},
                {field:"stock_name",title:"股票"},
                {field:"stock_code",title:"代码"},
                {field: "source", title: "来源"},
                {field: "editor", title: "编辑"},
                {field: "submit", title: "提交"}
            ],
            pagesize: 50,
            maxPageButtons: 5,
            rowNumbers: true
        });

        function refreshData(date) {
            $.ajax({
                url: "/ztReasonEditorData",
                async: true,
                type: 'POST',
                data: JSON.stringify({ 'date': date }),
                success: function (result) {
                    if (jQuery.type(result)=="string"){
                        var obj = JSON.parse(result);
                    }else{
                        var obj = result;
                    }
                    resultList = obj.resultList;
                    $('#date').val(obj.date);
                    clientManageDataTable.data(resultList, 'code');
                }
            })
        }
    function loadDate() {

        $.getJSON("/json", function (data) {
            var tradeDayList = data.trade_day;
            for (var i = 0; i < tradeDayList.length; i++) {
                var date = tradeDayList[i];
                if (date >= "2016-11-01") {
                    if (i == tradeDayList.length - 1) {
                        var html_str = "<option selected='selected' value='" + date + "'>" + date + "</option>";
                    } else {
                        var html_str = "<option value='" + date + "'>" + date + "</option>";
                    }
                    $('#date').append(html_str);
                }

            }
        })

    }
    loadDate();

    $("#date").change(function () {
        refreshData($("#date").val());
    });
    setTimeout(function () {
        refreshData("");
    }, 100);

</script>

</body>
</html>